<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./lib/react.development.js"></script>
    <script src="./lib/react-dom.development.js"></script>
    <script src="./lib/babel.min.js"></script>
</head>

<body>
    <div id="root"></div>

    <script type="text/babel">
        // 注意：挂载阶段的钩子函数除render以外在整个生命周期过程中只会执行一次
        class App extends React.Component {
            constructor(){
                super();
                this.h3Ref=React.createRef();
                this.state={a:1}
                console.log('一---constructor');
                
            }
            //即将挂载阶段  (快被废弃,加UNSAFE_ 取消警告)
            UNSAFE_componentWillMount(){
                this.setState.a=200
                console.log('二---componentWillMount',this.h3Ref);// {current: null}

            }
            render(){
                console.log('三---render');

                return(
                    <div>
                        <h3 ref={this.h3Ref}>{this.state.a}</h3>    
                    </div>
                )
            }
            // 组件挂载完毕
            componentDidMount(){
                console.log('四---componentDIdMount',this.h3Ref);// {current: h3}
            }
        }
        ReactDOM.createRoot(document.getElementById('root')).render(<App/>)
    </script>
</body>

</html>